package com.my.hotel.mapper;

import com.my.hotel.entity.Eva;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface EvaMapper {

    // 添加评论信息
    @Insert("insert into tb_eva values(null,#{evaContent},#{evaTime},#{userId},#{isNm},#{kfId},#{appStatus},#{evaClass},#{dzNum})")
    @Options(useGeneratedKeys=true,keyProperty = "id")
    public void addEva(Eva eva);

    // 添加图片关联
    @Insert("insert into tb_eva_img values(null,#{evaId},#{imageUrl})")
    public  void addEvaImage( String evaId, String imageUrl);

    //对点评进行全查询
    @Select("select * from tb_eva")
    public List<Eva> eva_all();

    //根据点评的星星数和时间进行查询
    @Select("<script>"+"select * from tb_eva" +
            " where eva_class in"+
            "<foreach collection=\"list\" open=\"(\" close=\")\" item=\"id\" separator=\",\" >" +
            "#{id}" +
            "</foreach>"+" order by eva_time desc"+ "</script>")
    public List<Eva> eva_pj(List ids);

    //根据点评的星星数和热门进行查询
    @Select("<script>"+"select * from tb_eva" +
            " where eva_class in"+
            "<foreach collection=\"list\" open=\"(\" close=\")\" item=\"id\" separator=\",\" >" +
            "#{id}" +
            "</foreach>"+" order by dz_num desc"+ "</script>")
    public List<Eva> eva_rm_px(List ids);


    //根据点评的星星数和时间进行查询
    @Select("<script>"+"select count(*) from tb_eva" +
            " where eva_class in"+
            "<foreach collection=\"list\" open=\"(\" close=\")\" item=\"id\" separator=\",\" >" +
            "#{id}" +
            "</foreach>"+"</script>")
    public int eva_hzc_num(List ids);

    //通过evaId对评论的点赞数进行修改
    @Update("update tb_eva set dz_num=dz_num+1 where id=#{id}")
    public int eva_dz_num(String id);

    //对点评进行全查询
    @Select("select * from tb_eva where id=#{id}")
    public Eva eva_Id(String id);

}
